<?php

namespace App\Console\Commands;

use App\Http\Model\Room;
use App\Http\Services\RoomMsgServices;
use App\Http\Services\RoomServices;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CloseAllOpenedRoom extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'closeAllOpenedRoom';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '关闭所有开播的房间';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            $allOpenedRoomArr = (new Room())->getOpenedRoomIdArr();
            $servicesRoom = new RoomServices();
            $servicesRoomMsg = new RoomMsgServices();
            foreach($allOpenedRoomArr as $roomId){
                $roomInfo = (new Room())->getRoomById($roomId);
                if ($roomInfo['business_type'] == 0){
                    $servicesRoom->clean($roomId);
                    $servicesRoomMsg->command_close($roomId);
                }

            }
        } catch (\Exception $e) {
            echo $e->getMessage();
        }

        return true;
    }
}